package com.yili.oa.service.impl;

import com.yili.oa.dao.extend.MenuExtendMapper;
import com.yili.oa.models.Menu;
import com.yili.oa.models.MenuExample;
import com.yili.oa.service.MenuService;
import com.yili.oa.utils.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    MenuExtendMapper menuMapper;

    public List<List<Menu>> getAll(){
        MenuExample menuExample = new MenuExample();
        menuExample.setOrderByClause("sort,sub_sort");
        List<Menu> list = menuMapper.selectByExample(menuExample);
        return ListUtils.get("sort", list);
    }

    public void add(Menu menu){
        int last = menuMapper.getMaxSort();
        menu.setSort(last+1);
        menu.setSubSort(0);
        menu.setUrl("main");
        menuMapper.insert(menu);
    }
}
